package com.share.device.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.PowerBank;
import com.share.device.service.IPowerBankService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import com.share.common.core.web.page.TableDataInfo;

/**
 * 充电宝
 * 
 * @author         
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/powerBank")
@Tag(name = "充电宝", description = "充电宝相关的增删改查操作")
public class PowerBankController extends BaseController
{
    @Autowired
    private IPowerBankService powerBankService;

    /**
     * 查询充电宝列表
     */
    @RequiresPermissions("device:powerBank:list")
    @Operation(summary = "充电宝列表")
    @GetMapping("/list")
    public TableDataInfo list(PowerBank powerBank)
    {
        startPage();
        List<PowerBank> list = powerBankService.selectPowerBankList(powerBank);
        return getDataTable(list);
    }

    /**
     * 导出充电宝列表
     */
    @RequiresPermissions("device:powerBank:export")
    @Operation(summary = "导出充电宝列表")
    @Log(title = "充电宝", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PowerBank powerBank)
    {
        List<PowerBank> list = powerBankService.selectPowerBankList(powerBank);
        ExcelUtil<PowerBank> util = new ExcelUtil<PowerBank>(PowerBank.class);
        util.exportExcel(response, list, "充电宝数据");
    }

    /**
     * 获取充电宝详细信息
     */
    @RequiresPermissions("device:powerBank:query")
    @Operation(summary = "获取充电宝详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(powerBankService.selectPowerBankById(id));
    }

    /**
     * 新增充电宝
     */
    @RequiresPermissions("device:powerBank:add")
    @Operation(summary = "新增充电宝")
    @Log(title = "充电宝", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PowerBank powerBank)
    {
        return toAjax(powerBankService.insertPowerBank(powerBank));
    }

    /**
     * 修改充电宝
     */
    @RequiresPermissions("device:powerBank:edit")
    @Operation(summary = "修改充电宝")
    @Log(title = "充电宝", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PowerBank powerBank)
    {
        return toAjax(powerBankService.updatePowerBank(powerBank));
    }

    /**
     * 删除充电宝
     */
    @RequiresPermissions("device:powerBank:remove")
    @Operation(summary = "删除充电宝")
    @Log(title = "充电宝", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(powerBankService.deletePowerBankByIds(ids));
    }
}
